from PO项目实战.对象层.user_page import UserPage


class UserBusiness(UserPage):
    
    def __init__(self, driver):
        super().__init__(driver)

    # 打开用户管理页面
    def open_user_page(self):
        self.driver.get(self.url)

    # 新增用户
    def add_user(self, username, password):
        self.add_user_btn_ele.click()
        self.add_username_ele.send_keys(username)
        self.add_password_ele.send_keys(password)
        self.add_gender_ele.click()
        # 去除学历元素的readonly属性
        # # js命令
        # js_command = "document.evaluate(\"{}\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)" \
        #              ".singleNodeValue.removeAttribute('readonly')".format(self.education_xpath)
        # # 执行js命令
        # self.driver.execute_script(js_command)
        # 选择博士
        self.add_education_ele1.click()
        self.add_education_ele2.click()
        self.add_date_ele.send_keys("2025-03-18 00:00:00")
        self.add_hobby_ele.click()
        self.add_brief_ele.send_keys("栗子测试")
        self.add_confirm_btn_ele.click()

    # 获取新增提示信息
    def get_add_alert_msg(self):
        return self.add_alert_ele.s_text

    # 编辑用户（列表中第一条数据）
    def edit_user(self, username):
        self.edit_btn_ele.click()
        self.edit_username_ele.send_keys(username)
        self.edit_confirm_btn_ele.click()

    # 获取编辑提示信息
    def get_edit_alert_msg(self):
        return self.edit_alert_ele.s_text

    # 查询
    def search_user(self, username):
        self.search_input_ele.send_keys(username)
        self.search_btn_ele.click()

    # 获取用户名列表第一个用户名，用于查询用户的判断
    def get_first_username(self):
        return self.first_line_username_ele.s_text

    # 删除用户（列表中第一条数据）
    def del_user(self):
        self.delete_btn_ele.click()
        self.delete_confirm_btn_ele.click()

    # 获取删除提示信息
    def get_del_alert_msg(self):
        return self.del_alert_ele.s_text



